package fredgolm;

public class PascalTriangle {

    private int depth;
    private int[][] t;

    //private PascalTriangle() {}
    public PascalTriangle(int aDepth) {
        depth = aDepth;
        t = new int[depth][];
        t[0] = new int[1];
        t[0][0] = 1;
        t[1] = new int[2];
        t[1][0] = t[1][1] = 1;

        for(int i=2; i<depth; ++i) {
           t[i] = new int[i+1];
           t[i][0] = t[i][i] = 1;
           for(int j=1; j<i; j++)  {
               t[i][j] = t[i-1][j-1] + t[i-1][j];
           }
        }

    }

    public int getBinomialCoef(int n, int k) {
        return t[n][k]; 
    }

    public void print() {
        for(int i = 0; i < depth; ++i) {
           // System.out.print("\t");//depth-i
            for(int k = 0; k < depth - i; ++k) {
                System.out.print("  ");
            }

            for(int j=0; j<i+1; ++j) {
                System.out.print(t[i][j] + "  ");
            }
            System.out.println("");
        }
    }

} 